package com.mayikt.days03;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName MayiktExecutor
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class MayiktExecutor {

    public void executor() {
    }

//    public static ExecutorService newFixedThreadPool(int corePoolSize,
//                                                     int maximumPoolSize, int queue) {
//        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
//                0L, TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<Runnable>(queue), new MyRejectedExecutionHandler());
//        // 缓存线程大小为Integer最大值
//    }

    public static ExecutorService newFixedThreadPool(int corePoolSize,
                                                     int maximumPoolSize, int queue) {
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(queue));
        // 缓存线程大小为Integer最大值
    }


    public static void main(String[] args) {
        // 最大线程数15，核心线程数10  缓存的队列5
//        ExecutorService executorService =
//                MayiktExecutor.newFixedThreadPool(10, 15, 5);
//        for (int i = 0; i < 21; i++) {
//            int finalI = i;
//            int finalI1 = i;
//            try {
//                executorService.execute(() -> {
//                    try {
//                        Thread.sleep(500);
//                    } catch (Exception e) {
//
//                    }
//                    System.out.println(Thread.currentThread().getName() + "," + finalI1);
//
//                });
//            } catch (Exception e) {
//                // 采用日志方式记录下 后期采用定时任务补偿。、
//                e.printStackTrace();
//
//            }
//        }
        // 请问执行结果 线程id 最大值是为多少 10 15


    }
}
